package com.example.homeworkmutualevaluation.utils;

import java.util.Random;

public class Base64 {
    private static final Random random = new Random();
    private final static char[] dic = new char[64];
    static  {
        int i = 0;
        for (char c = '0'; c <= '9'; c++)
            dic[i++] = c;
        for (char c = 'a'; c <= 'z'; c++)
            dic[i++] = c;
        for (char c = 'A'; c <= 'Z'; c++)
            dic[i++] = c;
        dic[i++] = '_';
        dic[i] = '-';
    }
    public static String toBase64(int n) {
        StringBuilder str = new StringBuilder();
        while (n > 0) {
            str.insert(0, dic[n & 63]);
            n >>= 6;
        }
        return str.toString();
    }
    public static String toBase64(long n) {
        StringBuilder str = new StringBuilder();
        while (n > 0) {
            str.insert(0, dic[(int) (n & 63)]);
            n >>= 6;
        }
        return str.toString();
    }
    public static char randNext() {
        return dic[random.nextInt() & 63];
    }
}
